<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 基础表格
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
              <el-table-column prop="Id" label="编号" width="100" align="center"></el-table-column>
                <el-table-column prop="F_name" label="姓名"></el-table-column>
                <el-table-column prop="Birth_data" label="出生日期"></el-table-column>
                <el-table-column prop="Life" label="生平"></el-table-column>
                <el-table-column prop="Glory" label="荣誉"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button>
                      <el-button
                          type="primary"
                          icon="el-icon-delete"
                          class="red"
                          @click="handleDelete(scope.row)"
                      >删除</el-button>
<!--                      <el-button-->
<!--                          type="primary"-->
<!--                          icon="el-icon-delete"-->
<!--                          class="red"-->
<!--                          @click="handleDelete(scope.add)"-->
<!--                      >添加</el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="成员编号">
                    <el-input v-model="partsData.Id"></el-input>
                </el-form-item>
				<el-form-item label="成员姓名">
                    <el-input v-model="partsData.F_name"></el-input>
                </el-form-item>
				<el-form-item label="出生日期">
                    <el-input v-model="partsData.Bith_data"></el-input>
          </el-form-item>
                <el-form-item label="生平经历">
                <el-input v-model="partsData.Life"></el-input>
                </el-form-item>
                <el-form-item label="荣誉">
                <el-input v-model="partsData.Glory"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
      import { familydelete,fetchgetfamily } from '../../api/index';
      import { fetchupdatefamily } from '../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            tableData: [],
            tempPartsData:{},
            partsData: {},
            multipleSelection: [],
            delList: [],
            query: {},
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
       this.getData()
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        getData() {
          fetchgetfamily().then(res =>{console.info(res)
            this.tableData=res.data.value
          })
        },
        handleDelete(row) {
          this.tempPartsData = row
          familydelete(this.tempPartsData).then(res=>{console.info(res)
            console.log(this.tempPartsData)
            console.log(res)
            window.location.reload()
          })
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.partsData = row;
            this.editVisible = true
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
           fetchupdatefamily(this.partsData).then(res =>{console.info(res)
             console.log(this.partsData)
             console.log(res)
          })
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
/*.handle-box {*/
/*    margin-bottom: 20px;*/
/*}*/

/*.handle-select {*/
/*    width: 120px;*/
/*}*/

/*.handle-input {*/
/*    width: 300px;*/
/*    display: inline-block;*/
/*}*/
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #FFFAFA;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
